package middle;

public class Solution_275 {

    public int hIndex(int[] citations) {
        int begin = 0, end = citations.length;
        while (begin <= end && end >= 0 && begin < citations.length) {
            int mid = (begin + end) >> 1;
            int h = citations.length - mid;
            if (citations[mid] >= h) {
                end = mid - 1;
            } else {
                begin = mid + 1;
            }
        }
        return end < 0 ? citations.length : begin >= citations.length ? 0 : citations.length - end - 1;
    }

    public static void main(String[] args) {
        Solution_275 model = new Solution_275();
        System.out.println(model.hIndex(new int[]{0,1,3,5,6}));
        System.out.println(model.hIndex(new int[]{1,2,100}));
        System.out.println(model.hIndex(new int[]{0}));
        System.out.println(model.hIndex(new int[]{1}));
        System.out.println(model.hIndex(new int[]{100}));
        System.out.println(model.hIndex(new int[]{0, 1}));
        System.out.println(model.hIndex(new int[]{11, 15}));
    }
}
